﻿<!DOCTYPE html>
<html>
<head>
    <title>注册账号</title>
    <link href="/SiteUI/Base.css" rel="stylesheet" />
    <link href="/LiberUI/Style/LiberUI.css" rel="stylesheet" />
    <link href="/SiteUI/Wechat/WegisteredAccount.css" rel="stylesheet" />
    <script src="/LiberUI/Scripts/jquery.js"></script>
    <script src="/LiberUI/Scripts/LiberUI.Base.js"></script>
    <script src="/LiberUI/Scripts/LiberUI.js"></script>
    <script src="/LiberUI/Scripts/LiberUI.Action.js"></script>
</head>
<body>
    <script>
        var ua = navigator.userAgent.toLowerCase();
        var isWeixin = ua.indexOf('micromessenger') != -1;
        var isAndroid = ua.indexOf('android') != -1;
        var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1);
        if (!isWeixin & !isAndroid & !isIos) {
            window.location = "/Register.html";
        };
        SoBiz.Template("_wxBase");
    </script>
    <div id="MainPart" section="PageBody">
        <div class="row procedure" >
         <img src="/SiteUI/Imgs/Wx-loginSteps1.png"/>
        </div>
        <div class="row acntForm">
            <div class="col-lg-8 col-lg-offset-2">
                <div class="col-lg-12 input-fill">
                    <input id="wx-phone" class="wx-input" type="text" placeholder="请输入手机号码">
                </div>
                <div class="col-lg-12 input-fill">
                    <div class="col-lg-6">
                        <input id="wx-captcha" class="wx-input" type="text" placeholder="请输入验证码">
                    </div>
                    <div class="col-lg-5 col-lg-offset-1 enableBtn" id="Captcha" >
                        发送验证码
                    </div>
                </div>
                <div class="col-lg-12 input-fill">
                    <input id="wx-pwd" class="wx-input" type="password" placeholder="请输入密码">
                </div>
                <div class="col-lg-12 input-fill">
                    <input id="wx-confirmPwd" class="wx-input" type="password" placeholder="再次输入密码">
                </div>
                <div class="col-lg-12" style="margin-top:2rem;margin-bottom:1rem">点击下一步意味您已阅读<a href="/WxPages/WxUserAgreement.html">《用户协议》</a></div>
                <div id="btnCreateAcnt" class="button btn-big">下一步</div>
                <div style="text-align:right;margin-top:2rem">已有帐号？&nbsp;&nbsp;<a href="/WxPages/WxUserBinding.html">点这里</a></div>
            </div>
        </div>
    </div>

    <script src="/LiberUI/Scripts/LiberUI.js"></script>
    <script src="/LiberUI/Scripts/LiberUI.Action.js"></script>
    <script src="/SiteUI/res_sobiz.js"></script>
    <script>
        Register = {
            NewAcnt: {
                src: null,
                phone: null,
                captcha: null,
                pass: null,
                name: null,
                headImg: null,
                openid: null,
                openname: null
            },     
            PhoneFormat: /^1[3,4,5,7,8]{1}[0-9]{9}$/,  //手机号格式验证的正则
            Countdown: 0,//倒计时秒数
            CountdownHandler: null,  //倒计时器
            checkPhone:function(){
                var phone = $("#wx-phone").vl();
                if (Register.PhoneFormat.test(phone))
                      return true;
                else 
                     return false;
            },
            sendCaptcha: function () {
                if (Register.checkPhone() === true){
                    if (Register.Countdown <= 0) {
                        Register.NewAcnt.phone = $("#wx-phone").vl();
                        $.getJSON("/Register/SendCaptcha", { phone: Register.NewAcnt.phone, forwhat: "newacnt" }, function (rtn) {
                            if (rtn.IsPositive) {
                                success("短信验证码已发送，5分钟内有效", 3, function () {
                                    Register.Countdown = 60;
                                    $("#Captcha").removeClass("enableBtn").addClass("disableBtn").vl( Register.Countdown+"秒");
                                    Register.CountdownHandler = setTimeout(Register.countInterval, 1000);
                                });
                            }
                            else {
                                error("验证失败，需要微信授权，或者在电脑上通过人机验证");
                                Register.Countdown =0;
                            }
                        }); 
                    }
                } else {
                    error("请填写正确的手机号码");
                }
            },
            countInterval: function (ev) {
                if (Register.Countdown > 0) {
                    Register.Countdown = Register.Countdown - 1;
                    $("#Captcha").vl(Register.Countdown + "秒");
                    Register.CountdownHandler = setTimeout(Register.countInterval, 1000);
                }
                else {
                    Register.Countdown = 0;
                    $("#Captcha").removeClass("disableBtn").addClass("enableBtn").vl("发送验证码");
                }
            },
            checkPwd: function () {
                var p = $("#wx-pwd");
                if (p.val().length >= 6 && p.vl().indexOf(" ") == -1) {
                    return true;
                } else {
                    return false;
                }
            },
            checkConfirmPwd: function () {
                var p = $("#wx-pwd");
                var cp = $("#wx-confirmPwd");
                if (cp.vl() !== p.vl()) {
                    return false;
                }
                else {
                    return true;
                }
            },
            checkCaptcha:function(){
                var c = $("#wx-captcha");
                if (c.vl()!=null&&c.vl().length>0) {
                    return true;
                }
                else {
                    return false;
                }
            },
            createAcnt: function () {
                if (!Register.checkPhone()) {
                    error("请填写正确手机号码");
                    return;
                } else if (!Register.checkCaptcha()) {
                    error("请填写正确验证码");
                }
                else if(! Register.checkPwd()){
                    error( "请填写6位以上密码且不能为空");
                    return;
                }
                else if (!Register.checkConfirmPwd()) {
                    error("两次密码不一致");
                    return;
                }
                else {
                    Register.NewAcnt.pass = $("#wx-confirmPwd").vl();
                    Register.NewAcnt.captcha = $("#wx-captcha").vl();
                    $("#btnCreateAcnt").vl("正在创建账号...").off("click", Register.createAcnt);
                    $.post("/Register/CreateAcnt", Register.NewAcnt, Register.createAcntEnd);
                }
               
            },
            createAcntEnd: function (rtn) {
                if (rtn.IsPositive) {
                       success("接下来将转到实名认证界面", 5, function () {
                            window.location = "/WxPages/WxAcntCertify.html";
                       });
                }
                else {
                    //TODO:创建账号失败
                    error("失败："+ ErrFormate(res_sobiz, rtn.ErrorSrc, rtn.ErrorCode, rtn.Error), 5, function () { $("#btnCreateAcnt").vl("下一步").on("click", Register.createAcnt); });
                }
            
            }
        }
        SoBiz.Ready(function () {
            $("#Captcha").on("click", Register.sendCaptcha);
            $("#btnCreateAcnt").on("click", Register.createAcnt);
        });

        //SoBiz.LoginWX(function () {
        //    Register.NewAcnt.headImg = WxUser.headimgurl;
        //    Register.NewAcnt.openid = WxUser.openid;
        //    Register.NewAcnt.openname = WxUser.nickname;
        //    Register.NewAcnt.src = "wechat";
        //});
    </script>
</body>
</html>
